﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data
Imports System.Configuration

Namespace DotNetNuke.Modules.ActiveForums.Data
    Public Class DataConfig
#Region "Private Members"
        Friend _connectionString As String
        Friend _objectQualifier As String
        Friend _databaseOwner As String
        Friend dbPrefix As String
        Private _providerConfiguration As DotNetNuke.Framework.Providers.ProviderConfiguration = DotNetNuke.Framework.Providers.ProviderConfiguration.GetProviderConfiguration("data")
#End Region
#Region "Constructors"
        Public Sub New()
            _connectionString = ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString

            _objectQualifier = ObjectQualifier
            If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
                _objectQualifier += "_"
            End If

            _databaseOwner = DataBaseOwner
            If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
                _databaseOwner += "."
            End If
            dbPrefix = _databaseOwner & _objectQualifier & "activeforums_"
        End Sub
#End Region
        Public Shared Function GetNull(ByVal Field As Object) As Object
            Return Null.GetNull(Field, DBNull.Value)
        End Function
        Public Property ObjectQualifier() As String
            Get
                Dim objProvider As DotNetNuke.Framework.Providers.Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), DotNetNuke.Framework.Providers.Provider)
                _objectQualifier = objProvider.Attributes("objectQualifier")
                If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
                    _objectQualifier += "_"
                End If
                Return _objectQualifier
            End Get
            Set(ByVal value As String)

            End Set
        End Property
        Public Property DataBaseOwner() As String
            Get
                Dim objProvider As DotNetNuke.Framework.Providers.Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), DotNetNuke.Framework.Providers.Provider)
                _databaseOwner = objProvider.Attributes("databaseOwner")
                If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
                    _databaseOwner += "."
                End If
                Return _databaseOwner
            End Get
            Set(ByVal value As String)

            End Set
        End Property
    End Class
End Namespace